Asp.Net Validation - RangeValidator

The RangeValentator does what the name means; It ensures that user input is within a specified range, you can use it to validate both numbers, stars and dates, which can be useful in a bunch of cases. Since we have since the last verified numbers, we will try with a date at this time.


Date:<br />
<asp:TextBox runat="server" id="txtDate" />
<asp:RangeValidator runat="server" id="rngDate" controltovalidate="txtDate" type="Date" minimumvalue="01-01-2006" maximumvalue="31-12-2006" errormessage="Please enter a valid date within 2006!" />
<br /><br />

If you are not from Europe, then the date format may look a little strange for you, where we use DD-MM-Yay. You can change this if the machine you are working on does not fit in the date format. Now, try to run the website, and enter a date in our new textbox. It is only valid if the date is within 2006, and a good side effect is that the date has also been checked for validity. Check out this screenshot, Which shows us that the verifier responds with an impossible date:

The RangeValidator in action

And once again, if client validation is not working, it will be caught in our Codewind, as shown with the expected FieldValidator. If you remember this part, make sure to check the first chapters!